package org.yjc.service;

import java.util.Optional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.yjc.entity.Student;
import org.yjc.repository.StudentRepository;

@Service
public class StudentService {
	@Autowired
	private StudentRepository studentDAO;

	public void save(Student student) {
		studentDAO.save(student);
	}
	
	public Page<Student> findAll(Pageable pageable) {
		return studentDAO.findAll(pageable);
	}

	public Student findById(Integer id) {
		Optional<Student> optional = studentDAO.findById(id);
		if(optional.isPresent()) {
			return optional.get();
		}
		return null;
	}
	
	public void deleteById(Integer ids) {
		studentDAO.deleteById(ids);
	}

	public Page<Student> findAll(Specification<Student> spec, Pageable pageable) {
		return studentDAO.findAll(spec, pageable);
	}

}
